package com.bella.api.utils;

/**
 * @author zsq
 * @create 2020-05-20-13:01
 */
public  class TestUtil {
    public static String generateBarcodeByUserId(Long userId, String regionBlockCode) {
        StringBuffer usb = new StringBuffer(userId.toString());
        int userIdMaxLength = 8;
        // user id is over max length
        if (usb.length() > userIdMaxLength) {
            return null;
        }
        // insert 0 into user id when its length less than max length
        while (usb.length() < userIdMaxLength) {
            usb.insert(0, 0);
        }
        // insert the specify code
        String[] barCodeList = "sh-lawson:1900,bj-lawson:1901,dl-lawson:1902,wh-lawson:1908,cq-lawson:1903,ah-lawson:1907,cs-lawson:1909,sy-lawson:1904".split(",");
        String barcodePref = "1900"; // 默认值
        for (String barStr : barCodeList) {
            String[] barcode = barStr.split(":");
            // 根据地区编号取不同的Barcode前缀
            if (regionBlockCode.equals(barcode[0])) {
                barcodePref = barcode[1];
                break;
            }
        }
        usb.insert(0, barcodePref);
        return BarcodeUtil.encodeEan13(usb.toString());
    }
}
